using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FetCo.Data;
using ADESSA.Business;
using ADESSA.Entities;
using FetCo.Framework;
using FetCo.Web;

public partial class Admin_TypeCompany : System.Web.UI.Page
{
    #region Variable
    protected int Id
    {
        get
        {
            object o = ViewState["Id"];
            if (o != null)
                return (int)o;
            return int.MinValue;
        }
        set
        {
            ViewState["Id"] = value;
        }
    }

    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        if (Request.QueryString["id"] != null)
        {
            this.Id = int.Parse(Request.QueryString["id"].ToString());
        }
        LoadData();
        LoadCurent();

    }
    #region LoadCurent
    private void LoadCurent()
    {
        HtmlGenericControl ulCompany = (HtmlGenericControl)Master.FindControl("ulCompany");
        ulCompany.Attributes.Add("class", "current");
        HtmlGenericControl liSubTypeCom = (HtmlGenericControl)Master.FindControl("liSubTypeCom");
        liSubTypeCom.Attributes.Add("class", "sub_show");
        HtmlControl divSelectSubCom = (HtmlControl)Master.FindControl("divSelectSubCom");
        divSelectSubCom.Attributes.Add("class", "select_sub show");
    }
    #endregion
    #region LoadData
    private void LoadData()
    {
        ADESSA.Entities.TypeCompany _TypeCompany = new ADESSA.Entities.TypeCompany();
        if (this.Id != int.MinValue && this.Id != 0)
        {
            _TypeCompany = TypeCompanyService.GetTypeCompany(this.Id);
            if (_TypeCompany != null)
            {
                txtName.Value = _TypeCompany.Title;
                txtOrder.Value = _TypeCompany.SortOrder.ToString();

            }
        }
    }
     #endregion
    #region VoidSave and Reset
    protected void btnsave_Click(object sender, EventArgs e)
    {
        ADESSA.Entities.TypeCompany _TypeCompany = new ADESSA.Entities.TypeCompany();
        if (this.Id != int.MinValue && this.Id != 0)
        {
            _TypeCompany = TypeCompanyService.GetTypeCompany(this.Id);
        }
        _TypeCompany.Title = txtName.Value.Trim();
        if (!string.IsNullOrEmpty(txtOrder.Value.Trim()))
            _TypeCompany.SortOrder = int.Parse(txtOrder.Value.Trim());
        else
            _TypeCompany.SortOrder = 10;
        if (this.Id != int.MinValue && this.Id != 0)
        {
            TypeCompanyService.UpdateTypeCompany(_TypeCompany);
            Response.Redirect("TypeCompanyList.aspx");
        }
        else
        {
            _TypeCompany.Enable = true;

            TypeCompanyService.CreateTypeCompany(_TypeCompany);
            Response.Redirect("TypeCompanyList.aspx");
        }
    }
    protected void btnexit_Click(object sender, EventArgs e)
    {
        Response.Redirect("TypeCompanyList.aspx");
    }
    #endregion
}
